package njust.csc.aeapi.controller

import njust.csc.aeapi.entity.ApkWhiteList
import njust.csc.aeapi.model.MessageModel
import njust.csc.aeapi.service.ApkWhitelistService
import njust.csc.aeapi.utils.LogRequest
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

/**
 * @Author ZhouHang
 * @Date 24/8/8 周四
 */
@RestController
@RequestMapping("/api/whitelist")
class ListController @Autowired constructor(
    private val apkWhitelistService: ApkWhitelistService
) {
    @GetMapping("/find_all")
    fun findAll(): List<ApkWhiteList> {
        return apkWhitelistService.findAll()
    }

    @PostMapping("/add")
    fun addOne(apkWhitelist: ApkWhiteList): MessageModel {
        apkWhitelistService.saveOrUpdate(apkWhitelist)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }

    @PutMapping("/update")
    fun updateOne(apkWhitelist: ApkWhiteList): MessageModel {
        apkWhitelistService.saveOrUpdate(apkWhitelist)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }

    @DeleteMapping("/delete/{id}")
    fun deleteOne(@PathVariable("id") id: Int): MessageModel {
        apkWhitelistService.delete(id)
        return MessageModel(
            code = 2000,
            message = "Success"
        )
    }
}
